﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;

namespace ERP_RORZE.Product.BasicList
{
    public partial class ctrlExpence : DevExpress.XtraEditors.XtraUserControl
    {
        ClsBasicListDAO clsBasiclistDAO = new ClsBasicListDAO();
        DataTable dt;
        Expence b = new Expence();

        void Reload(object sender, EventArgs e)
        {
            dt = clsBasiclistDAO.GetAllExpence();
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();

        }
        public ctrlExpence()
        {
            InitializeComponent();
            
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            b.ExpenceID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"ExpenceID").ToString();
            clsBasiclistDAO.DeleteExpence(b);
            Reload(sender, e);
        }

        private void ctrlExpence_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            frm_ExpenceAdd frmAdd = new frm_ExpenceAdd();
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.Text = "Nhập mới";
            frmAdd.Show();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            frm_ExpenceEdit frmEdit = new frm_ExpenceEdit();
            frmEdit.Reload += new EventHandler(Reload);
            frmEdit.ExpenceID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ExpenceID").ToString();
            frmEdit.Description = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Description").ToString();
            frmEdit.LaborExp = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LaborExp").ToString();
            frmEdit.Show();

        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            btnAdd_Click(sender,e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            btnEdit_Click(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            btnDelete_Click(sender, e);
        }
    }
}
